package com.example.springbootdeom.dao;

import com.example.springbootdeom.entity.Course;
import com.example.springbootdeom.entity.Result;
import com.example.springbootdeom.entity.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentDao {
    //查看个人信息
    @Select("select * from user where id=#{id} and status=2")
    public Student getstudent(int id);
    //修改个人用户名和密码
    @Update("UPDATE `user` SET uname=#{uname} ,password=#{password} WHERE id =#{id} and `status`=2")
    public boolean updateMsg(Student student);
    //选课(需要传入学生id跟课程id)
    @Insert("INSERT INTO courseresults (stu_id,course_id) VALUES(#{stuId},#{courserId});")
    public boolean addCourse(@Param("stuId") int stuId, @Param("courserId") int courserId);
    //查询学生所有课程信息(需要学生id)(当前的查询语句还在有问题：查询出来的语句重复)
    @Select("SELECT  c.Cid,c.Cname,c.Ctype,c.Ccredit,u.name,c.Chour FROM courseresults AS r,course AS c,`user` AS u WHERE  r.course_id=c.Cid  AND c.teacher_id=u.id AND r.stu_id=#{id}")
    public List<Course> getAllCourse(int id);
    //查询个人成绩(根据课程id)

    public Result getResult(int id,int cid);
}